package com.cavedroid;

import java.lang.reflect.Array;

public class CyclicQueue<T> {
	
	int size;
	
	int dimensions;
	
	int position = 0;
	
	private final T[] array;
	
	private T[] temp;
	
	public CyclicQueue(Class<T> type, int size, int dimensions) {
		this.size = size;
		this.dimensions = dimensions;
		this.array = (T[])Array.newInstance(type, size*dimensions);
		this.temp = (T[])Array.newInstance(type, dimensions);
	}
	
	public void offer(T[] o) {
		for (int i = 0; i < dimensions; i++) {
			array[position+i] = o[i];
		}
		position += dimensions;
		position %= size*dimensions;
	}
	
	public T[] get(int index) {
		for (int i = 0; i < dimensions; i++) {
			temp[i] = array[(index*dimensions + position + i) % (size*dimensions)];
		}
		return temp;
	}
}
